const vscode = require('vscode');

class MirConfigWebviewProvider {
    constructor(context) {
        this._context = context;
        this._view = undefined;
    }

    resolveWebviewView(webviewView, context, token) {
        console.log("fdsfds");
        
        this._view = webviewView;

        webviewView.webview.options = {
            enableScripts: true,
            localResourceRoots: [vscode.Uri.file(path.join(this._context.extensionPath, 'media'))]
        };

        webviewView.webview.html = this._getHtmlForWebview(webviewView.webview);

        webviewView.webview.onDidReceiveMessage(message => {
            switch (message.command) {
                case 'alert':
                    vscode.window.showInformationMessage(message.text);
                    return;
            }
        }, undefined, this._context.subscriptions);
    }

    _getHtmlForWebview(webview) {
        const scriptUri = webview.asWebviewUri(vscode.Uri.file(path.join(this._context.extensionPath, 'media', 'main.js')));
        const styleUri = webview.asWebviewUri(vscode.Uri.file(path.join(this._context.extensionPath, 'media', 'main.css')));

        return `
            <!DOCTYPE html>
            <html lang="en">
            <head>
                <meta charset="UTF-8">
                <meta name="viewport" content="width=device-width, initial-scale=1.0">
                <title>配置面板</title>
                <link href="${styleUri}" rel="stylesheet">
            </head>
            <body>
                <h1>配置面板</h1>
                <form id="configForm">
                    <label for="name">Name:</label>
                    <input type="text" id="name" name="name"><br><br>
                    <label for="email">Email:</label>
                    <input type="email" id="email" name="email"><br><br>
                    <label>Gender:</label><br>
                    <input type="radio" id="male" name="gender" value="male">
                    <label for="male">Male</label><br>
                    <input type="radio" id="female" name="gender" value="female">
                    <label for="female">Female</label><br><br>
                    <label for="hobbies">Hobbies:</label><br>
                    <input type="checkbox" id="reading" name="hobbies" value="reading">
                    <label for="reading">Reading</label><br>
                    <input type="checkbox" id="gaming" name="hobbies" value="gaming">
                    <label for="gaming">Gaming</label><br>
                    <input type="checkbox" id="traveling" name="hobbies" value="traveling">
                    <label for="traveling">Traveling</label><br><br>
                    <input type="submit" value="Submit">
                </form>
                <script src="${scriptUri}"></script>
            </body>
            </html>
        `;
    }
}

module.exports = MirConfigWebviewProvider;